package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.StrategyLikeInfo;
import com.example.mountainwalker.service.StrategyLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/strlike")
@CrossOrigin
public class StrategyLikeController {
    @Autowired
    private StrategyLikeService strategyLikeService;

    @GetMapping("/find")
    public ResponseEntity<StrategyLikeInfo> getStrategyLikeById(@RequestParam Integer id) {
        return ResponseEntity.ok(strategyLikeService.getStrategyLikeInfoById(id));
    }

    @GetMapping("/list")
    public ResponseEntity<List<StrategyLikeInfo>> getAllStrategyLikes() {
        return ResponseEntity.ok(strategyLikeService.getStrategyLikeInfo());
    }

    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Integer> deleteStrategyLikeById(@PathVariable Integer id) {
        return ResponseEntity.ok(strategyLikeService.deleteStrategyLikeInfoById(id));
    }

    @PostMapping("/insert")
    public ResponseEntity<Integer> insertStrategyLikeInfo(@RequestBody StrategyLikeInfo strategyLikeInfo) {
        System.out.println("接收到的数据：" + strategyLikeInfo);
        return ResponseEntity.ok(strategyLikeService.insertStrategyLikeInfo(strategyLikeInfo));
    }
}